//图片剧中算法 // w:真实宽度 h:真实高度 _w:显示区域宽度 _h:显示区域高度
module.exports = function(args){
    args.type = args.type || 1;
    var w = args.w,h = args.h;
    var box_w = args._w,box_h = args._h;
    var _w,_h,_t,_l;
    if(w <= box_w && h <= box_h){
        _w = w;
        _h = h;
    }else{
        switch(args.type){
            case 'x'://x轴铺满
                if(w >= box_w){
                    _w = box_w;
                    _h = scaleH();
                }
                break;
            case 'y'://y轴铺满
                if(h >= box_h){
                    _h = box_h;
                    _w = scaleW();
                }
                break;
            default://完全限制在容器内
                if(w >= box_w){
                    _w = box_w;
                    _h = scaleH();
                    if(_h > box_h){
                        _h = box_h;
                        _w = scaleW();
                    }
                }else if(h >= box_h){
                    _h = box_h;
                    _w = scaleW();
                }
                break;
        }
    }
    function scaleW(){
        return box_h / h * w;
    }
    function scaleH(){
        return box_w / w * h;
    }
    _l = (box_w - _w) / 2;
    _t = (box_h - _h) / 2;
    return [_w,_h,_t,_l,_w / w];//width height top left
}